﻿
<!DOCTYPE html>
<html lang="en">
<head>
    <title>合作社</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="../assets/layui/css/layui.css">
    <link rel="stylesheet" href="../css/plugins/select-multiple.css">
    <link rel="stylesheet" href="../css/reset.css">
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/index.css">
    <link rel="stylesheet" href="../css/plugins/plugin-condition.css">
    <link rel="stylesheet" href="../assets/layui-v2.4.5/css/layui.css">
</head>
<style>
    #big_div {
        width: 100%;
        height: 100%;
    }

    #search {
        margin-top: 20px;
    }

    #type_div {
        width: 200px;
    }

    .layui-btn-normal {
        background-color: #5FB878;
    }

    #table_div {
        margin-top: 20px;
        margin-left: 10px;
    }
</style>
<body>

<br>
<!--<div id="big_div">-->
    <!--<div id="search">-->
<!-- 搜索栏目开始-->
<form  class="layui-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">年份</label>
            <div class="layui-input-block">
                <input name="year" type="text" class="layui-input" id="year" placeholder="yyyy">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <div class="layui-input-inline" id="type_div">
                    <select name="type" id="type" lay-verify="required">
                        <option value="0">全部</option>
                        <option value="1">气象灾害</option>
                        <option value="2">低温</option>
                        <option value="3">风雹</option>
                        <option value="4">干旱</option>
                        <option value="5">洪涝</option>
                    </select>
                </div>
            </div>
        </div>
        <button class="layui-btn layui-btn-sm"  lay-submit="" lay-filter="demo1">搜索</button>
    </div>
</form>
        <!--<div id="table_div">-->
            <!--<table id="demo" lay-filter="test"></table>-->
        <!--</div>-->
    <!--</div>-->
<!--</div>-->
<!-- 搜索栏目结束-->

<!-- 表格开始-->
<table id="farmstabae" lay-filter="barDemo"></table>
<script type="text/html" id="barDemo">
    <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>-->
    <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
</script>
<!-- 表格开始-->

<!-- 弹出层  -->
<div id="ckuserSub" style="display: none">
    <form  class="layui-form" action="">
        <input type="hidden" id="id" name="id" >
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">市</label>
                <div class="layui-input-block">
                    <input type="text" id="city" name="city" lay-verify="title" autocomplete="off" placeholder="" class="layui-input" disabled="disabled">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">公司名称</label>
                <div class="layui-input-block">
                    <input type="text" id="area" name="area" lay-verify="title" autocomplete="off" placeholder="" class="layui-input" disabled="disabled">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">公司名称</label>
                <div class="layui-input-block">
                    <input type="text" id="companyName" name="companyName" lay-verify="title" autocomplete="off" placeholder="" class="layui-input" disabled="disabled">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">电话</label>
                <div class="layui-input-block">
                    <input type="text" id="mobile" name="mobile" lay-verify="title" autocomplete="off" placeholder="" class="layui-input" disabled="disabled">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">法人</label>
                <div class="layui-input-block">
                    <input type="text" id="legalPerson" name="legalPerson" lay-verify="title" autocomplete="off" placeholder="" class="layui-input" disabled="disabled">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">经营范围</label>
                <div class="layui-input-block">
                    <input type="text" id="cropName" name="cropName" lay-verify="title" autocomplete="off" placeholder="" class="layui-input" disabled="disabled">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">注册资金</label>
                <div class="layui-input-block">
                    <input type="text" id="registerMoney" name="registerMoney" lay-verify="title" autocomplete="off" placeholder="" class="layui-input" disabled="disabled">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-block">
                    <input type="text" id="address" name="address" lay-verify="title" autocomplete="off" placeholder="" class="layui-input" disabled="disabled">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">成立日期</label>
                <div class="layui-input-block">
                    <input type="text" id="establishTime" name="establishTime" lay-verify="title" autocomplete="off" placeholder="" class="layui-input" disabled="disabled">
                </div>
            </div>

        </div>
        <div  class="layui-inline" style="float:right;left:-20px;">
            <!-- <button class="layui-btn layui-btn-sm" id="xganniu" lay-submit=""  lay-filter="xgusersj">修改</button> -->
            <!-- <button class="layui-btn layui-btn-sm" id="tjanniu" lay-submit=""  lay-filter="saveusersj">添加</button> -->
        </div>
    </form>
</div>
<script type="text/javascript" src="../assets/jquery/jquery.min.js" charset="utf-8"></script>
<script type="text/javascript" src="../assets/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">

    var apidz = "http://10.172.13.58:8088/MDRMSWebService/largeFams/";
    // var areaCode = JSON.parse(localStorage.getItem("areaCode"));//获取 点击存储的code值
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#farmstabae'
            ,id:'idTest'
            ,url: apidz + 'getDisterYearBook'
            ,skin: 'row'							//皮肤，无上下边框
            ,even: true								//皮肤，开启隔行显示
            ,page: true //开启分页
            ,limit:10
            ,limits:[10,20,30,40]
            ,cols: [[ //表头
                {field: 'year', title: '年', width: 120,align: 'center'}
                , {field: 'type', title: '灾害类型', align: 'center'}
                , {field: 'sSq', title: '受灾面积（万亩）',width: 120, align: 'center'}
                , {field: 'cSq', title: '成灾面积（万亩）', width: 120,align: 'center'}
                , {field: 'jSq', title: '绝收面积（万亩）', width: 120,align: 'center'}
                , {field: 'bSq', title: '播种面积(万亩)', width: 120, align: 'center'}
                , {field: 'dSq', title: '单位面积产量(公斤)', width: 120, align: 'center'}
                , {field: 'cRatio2', title: '成灾率', width: 120, align: 'center'}
                , {field: 'sRatio2', title: '受灾率', width: 120, align: 'center'}
                , {field: 'disStr2', title: '灾害强度', width: 120, align: 'center'}
                , {field: 'foodReduce', title: '因灾粮食减产', width: 120, align: 'center'}
                ,{field: 'right', width:178, align:'center', toolbar: '#barDemo'}
            ]]
        });
    });

    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(farmstabae)', function(obj){
            console.log(obj)
        });

        //监听工具条
        table.on('tool(barDemo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){//查看
                $("#xganniu").hide();
                jzbjsrk();
                ckuserxx(data);
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    ajaxdy("delAgrById?id="+JSON.stringify(data.id));
                    obj.del();
                    layer.close(index);
                });
            }else if(obj.event === 'edit'){
                $("#xganniu").show();
                bjsrk();
                ckuserxx(data);
            }
        });


        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        //年选择器
        laydate.render({
            elem: '#year'
            , type: 'year'
        });

        //监听查询提交
        layui.form.on('submit(demo1)', function(data){
            reload(data);
            return false;
        });
        //监听修改提交
        layui.form.on('submit(xgusersj)', function(data){
            ajaxdy("updateAgrById","post",data.field);
            layer.closeAll();
            reload(null);
            return false;
        });
    });

    //刷新表格
    function reload (data){
        if(data != null){
            layui.table.reload('idTest', {
                url:apidz+'getDisterYearBook'
                ,where: data.field //设定异步数据接口的额外参数
                //,height: 300
            });
        }else{
            layui.table.reload('idTest', {
                url: apidz+'getDisterYearBook'
                //,height: 300
            });
        }
    }

    //编辑输入框
    function bjsrk(){
        $("#content").attr("disabled",false);
    }
    //禁止编辑输入框
    function jzbjsrk(){
        $("#content").attr("disabled",true);
    }
    //查看
    function ckuserxx(data){
        dataqk();
        if(data != null){
            datatc(data);
        }
        layer.open({
            type: 1,
            shade: false,
            title: '查看信息',
            area: ['950px', '560px'],
            shadeClose: true, //点击遮罩关闭
            closeBtn: 1,
            content: $('#ckuserSub'),
            end:function(){
                $("#ckuserSub").hide();
            },
        });
    }

    //弹出层数据填充
    function datatc(data){
        $("#city").val(data.city);
        $("#area").val(data.area);
        $("#companyName").val(data.companyName);
        $("#mobile").val(data.mobile);
        $("#legalPerson").val(data.legalPerson);
        $("#cropName").val(data.cropName);
        $("#registerMoney").val(data.registerMoney);
        $("#address").val(data.address);
        $("#establishTime").val(data.establishTime);
        renderForm();
    }
    //重新渲染表单
    function renderForm(){
        layui.use('form', function(){
            var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加()
            form.render();
        });
    }

    function ajaxdy(dyurl,typr,data){
        var fhdata = null;
        $.ajax({
            url:apidz+dyurl,
            type:typr, //GET
            async:false,  //或false,是否异步
            data:data,
            dataType:'json',
            success:function(data){
                fhdata = data;
            }, error:function(xhr,textStatus){
                layer.msg('数据访问异常！');
            }
        });
        return fhdata;
    }
    //弹出层数据清空
    function dataqk(){
        $("#city").val("");
        $("#area").val("");
        $("#companyName").val("");
        $("#mobile").val("");
        $("#legalPerson").val("");
        $("#cropName").val("");
        $("#registerMoney").val("");
        $("#address").val("");
        $("#establishTime").val("");
    }

</script>

</body>

</html>